require.config({
  baseUrl: 'dist/',
  waitSeconds: 30,
  paths: {
    '@server': '/!',
    '@': '/dist',

    'yvan-ui-wotu': '/node_modules/yvan-ui-wotu/dist/yvan-ui-wotu',
    'tslib': '/node_modules/tslib/tslib',
    'jquery': '/static/jquery/jquery-1.11.1.min',

    'pinyinTong': '/static/pinyin/pinyin_dict_withtone',
    'pinyinUtil': '/static/pinyin/pinyinUtil',
    'xlsx_export': '/static/layui_exts/excel',
  },
  map: {
    '*': {
      css: '/static/require-css/css.min.js'
    },
  },
  shim: {
    'yvan-ui-wotu': {
      deps: [
        'css!/node_modules/yvan-ui-wotu/dist/yvan-ui-wotu.css',
        'css!/static/font-awesome/css/font-awesome.min.css',
      ]

    }
  }
})

window['process'] = {
  env: {
    NODE_ENV: 'production'
  }
}
window['errorKeys'] = []

require(['yvan-ui-wotu', 'app', 'pinyinTong', 'xlsx_export'], function (YvanUI, app) {
  window['YvanUI'] = YvanUI
  window['_'] = YvanUI.lodash

  // 载入词典完毕之后，再载入 pinyinUtil
  require(['pinyinUtil'], function () {
    window.getFirstPinyin = function (value) {
      return window.pinyinUtil.getFirstLetter(value, true).join('')
    }

    window.getFirstPinyin2 = function (str) {
      let _ = YvanUI.lodash
      let result = []
      if(!str){
        return ''
      }
      for (var i = 0; i < str.length; i++) {
        var unicode = str.charCodeAt(i);
        var ch = str.charAt(i);
        if (unicode >= 19968 && unicode <= 40869) {
          //@ts-ignore
          result.push(window.getFirstPinyin(ch));
        } else {
          result.push(_.toUpper(ch));
        }
      }
      return result.join("")
    }

    YvanUI.extend({
      pinyinFunction: window.getFirstPinyin2
    })
  });

  app.default(document.getElementById('app'))
})
